package com.ipad.ui.fragmen;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.ipad.R;
import com.ipad.utils.MCodeUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class ImgDialogFragment extends DialogFragment {
    @BindView(R.id.dialog_code_img)
    ImageView dialog_code_img;
    private String TAG = "img_dialog";

    public ImgDialogFragment() {
        // Required empty public constructor
        setStyle(STYLE_NO_TITLE,0);
    }

    public static ImgDialogFragment newInstance(String code) {

        Bundle args = new Bundle();
        args.putString("oneCode",code);
        ImgDialogFragment fragment = new ImgDialogFragment();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View inflate = inflater.inflate(R.layout.fragment_img_dialog, container, false);
        ButterKnife.bind(this,inflate);
        init();
        return inflate;
    }

    private void init() {
        String oneCode = getArguments().getString("oneCode");
        Log.e(TAG, "init: "+oneCode );
//        int w = getResources().getDisplayMetrics().widthPixels/3;
//        int h = getResources().getDisplayMetrics().widthPixels/5;
        MCodeUtils.setOneCodeImage(oneCode,dialog_code_img,getActivity());
    }

    @Override
    public void onStart() {
        super.onStart();
        getDialog().getWindow().setWindowAnimations(R.style.windowAnimotion);
        getDialog().setCanceledOnTouchOutside(true);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(R.style.img_loading_style,R.style.img_loading_style);
    }
}
